//#include <emalloc.h>
//#include <stdutils.h>
//#include <buffer.h>
//#include <string.h>
//#include <pthread.h>
//#include <iterator_utils.h>
//
//#include "file.h"
//
//void sfile_flush(FILE* fp, SFile* file) {
//	int name_len = strlen(file->filename);
//	fwrite(&name_len, sizeof(name_len), 1, fp);
//	fwrite(file->filename, name_len, 1, fp);
//	fwrite(&file->timestamp, sizeof(file->timestamp), 1, fp);
//	fwrite(&file->size, sizeof(file->size), 1, fp);
//	fwrite(file->data, file->size, 1, fp);
//}
//
//SFile* sfile_load(FILE* fp) {
//	SFile* file = emalloc(sizeof(SFile));
//	memset(file->filename,0,sizeof(file->filename));
//	int name_len = 0;
//	fread(&name_len, sizeof(name_len), 1, fp);
//	fread(file->filename, name_len, 1, fp);
//	fread(&file->timestamp, sizeof(file->timestamp), 1, fp);
//	fread(&file->size, sizeof(file->size), 1, fp);
//	file->data = emalloc(file->size);
//	fread(file->data, file->size, 1, fp);
//	return file;
//}
//
//SFile* sfile_load_not_data(FILE* fp) {
//	SFile* file = emalloc(sizeof(SFile));
//	memset(file->filename,0,sizeof(file->filename));
//	int name_len = 0;
//	fread(&name_len, sizeof(name_len), 1, fp);
//	fread(file->filename, name_len, 1, fp);
//	fread(&file->timestamp, sizeof(file->timestamp), 1, fp);
//	fread(&file->size, sizeof(file->size), 1, fp);
//	fseek(fp, file->size, SEEK_CUR);
//	return file;
//}
//
//void sfile_to_buffer(SFile* file,Buffer* buf) {
//	buffer_write(buf, file->filename, sizeof(file->filename));
//	buffer_write(buf, &file->timestamp, sizeof(file->timestamp));
//	buffer_write(buf, &file->size, sizeof(file->size));
//	buffer_write(buf, file->data, file->size);
//}
//
//void buffer_to_sfile(Buffer* buf,SFile* file) {
//	memset(file->filename,0,sizeof(file->filename));
//	buffer_read(buf,file->filename,sizeof(file->filename));
//	buffer_read(buf,&file->timestamp,sizeof(file->timestamp));
//	buffer_read(buf,&file->size,sizeof(file->size));
//
//	file->data = buffer_load(buf, file->size);
//}
//
//Buffer* sfile_info_list_to_buffer(Buffer* buf,List* sfile_info_list){
//	int size = list_size(sfile_info_list);
//	buffer_write(buf,&size,sizeof(size));
//	SFileInfo* file = NULL;
//	iterator_list(sfile_info_list)
//	{
//		file = list_next(sfile_info_list);
//		buffer_write(buf, file->filename, sizeof(file->filename));
//		buffer_write(buf, &file->size, sizeof(file->size));
//		buffer_write(buf, &file->timestamp, sizeof(file->timestamp));
//	}
//	return buf;
//}
//
//List* buffer_to_sfile_info_list(Buffer* buf){
//	List* list = list_new();
//	int size = 0;
//	buffer_read(buf,&size,sizeof(size));
//	for (int i = 0; i < size; i++) {
//		SFileInfo* file = emalloc(sizeof(SFileInfo));
//		buffer_read(buf,file->filename,sizeof(file->filename));
//		buffer_read(buf,&file->size,sizeof(file->size));
//		buffer_read(buf,&file->timestamp,sizeof(file->timestamp));
//		list_push_front(list,file);
//	}
//	return list;
//}
//
//void sfile_destory(void* obj) {
//	SFile* file = obj;
//	if (file != NULL) {
//		efree(file->data);
//		efree(file);
//	}
//}
//
//void sfile_destory_void(void* f) {
//	SFile* file = f;
//	if (file != NULL) {
//		efree(file->data);
//		efree(file);
//	}
//}
//
//void* sfile_destory_not_data(SFile* file) {
//	if (file != NULL) {
//		efree(file);
//	}
//	return NULL;
//}
//
////SFile
//
//SFile* sfile_init(){
//	SFile* file = emalloc(sizeof(SFile));
//	file->data = NULL;
//	return file;
//}
//
//SFile* sfile_create(const char* filename, char* data, int32_t size, int64_t timstamp) {
//	SFile* file = emalloc(sizeof(SFile));
//	memset(file->filename,0,sizeof(file->filename));
//	strcpy(file->filename, filename);
//	if (timstamp <= 0) {
//		file->timestamp = timer_get_micro_second();
//	} else {
//		file->timestamp = timstamp;
//	}
//	file->size = size;
//	file->data = malloc(size);
//	memcpy(file->data,data,size);
//	return file;
//}
//
//Buffer* sfile_list_to_buffer(Buffer* buf,List* sfile_list){
//	SFile* file = NULL;
//	int size = list_size(sfile_list);
//	buffer_write(buf,&size,sizeof(size));
//	iterator_list(sfile_list)
//	{
//		file = list_next(sfile_list);
//		sfile_to_buffer(file, buf);
//	}
//	return buf;
//}
//
//void buffer_to_sfile_list(Buffer* buf,List* list){
//	SFile* file = NULL;
//	int size = 0;
//	buffer_read(buf,&size,sizeof(size));
//	for(int i = 0; i < size;i++){
//		file = emalloc(sizeof(SFile));
//		buffer_to_sfile(buf,file);
//		list_push_front(list,file);
//	}
//}
//
////common
//
//int read_file(const char* filename,int32_t size,int offset,char* dest,pthread_rwlock_t lock){
//	pthread_rwlock_rdlock(&lock);
//	FILE* fp = NULL;
//	if ((fp = fopen(filename, "rb")) == NULL) {
//		return -1;
//	}
//	fseek(fp, offset, SEEK_SET);
//	fread(dest,size,1,fp);
//	fclose(fp);
//	pthread_rwlock_unlock(&lock);
//	return 1;
//}
//
//int write_file(const char* filename,int32_t size,int offset,char* src,pthread_rwlock_t lock){
//	pthread_rwlock_wrlock(&lock);
//	FILE* fp = NULL;
//	if ((fp = fopen(filename, "wb")) == NULL) {
//		return -1;
//	}
//	fseek(fp, offset, SEEK_SET);
//	fwrite(src,size,1,fp);
//	fclose(fp);
//	pthread_rwlock_unlock(&lock);
//	return 1;
//}
